<style scoped>
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }
  .weui-loadmore_line .weui-loadmore__tips {
    background-color: #eee;
  }
  .rj-cell.max span{
    font-size: 16px;
    padding-right: 20px;
  }
  .rj-cell label {
    color: #333;
    font-size: 14px;
    width: 44%;
    display: inline-block;
    padding: 5px 3%;
    text-align: right;
  }
  .rj-cell span {
    font-size: 14px;
    color: #333;
    display: inline-block;
    width: 50%;
  }
  .rj-cell.note label{
    float: left;
  }
  .rj-cell.note span{
    width: 80%;
    display: inline-block;
  }
  .weui-cells {
    margin-top: 0;
  }
  .weui-cells_form {
    background: #fbfbfb;
  }
  .weui-cell {
    background: #fff;
  }
  .weui-cells__title {
    text-align: left;
  }
  .oitem {
    padding: 3px;
  }
  .hide {
    display: none;
  }
  #acts {
    font-size: 0;
  }
  #acts span {
    font-size: 14px;
  }
  .halfbtn {
    display: inline-block;
    width: 49%;
  }
  h2 {font-size: 17px;color: #000000; display : inline}
  input[readonly="readonly"]{
    background: #ffffff;
    color: #ccc;
  }
</style>
<template>
  <div>
    <div style="height: 50px; line-height: 50px; background: #f7f7f7; text-align: center; font-size: 16px; border-bottom: 1px solid #bdbbbc; position: relative">
      调价
      <a href="javascript:;" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="../../assets/back.png" style="width: 20px" />
      </a>
    </div>
    <div class="weui-cells weui-cells_form">
<!--      <form action="/sales/Sellform!saveOrUpdate .action?openid=${openid}" method="post" id="formid">-->
      <form action="/api/sellform/add" method="post"  id="formid">


        <div class="oitem"  v-for="(item, index) in data" :key="item.guid">
          <div class="weui-cells__title">货品明细 <h2 >({{index + 1}})</h2>
            <input type="hidden"  :name="appand(index,'guid')" :value="item.guid" />
            <input type="hidden"  name="orderguid" :value="guid" />
            <p id="acts" style="float: right;color: #1aad19;">
              <!--<span id="addItem" style="padding-right: 5px;">添加</span>-->
            </p>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label for="productguid1" class="weui-label">产品</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text" readonly="true" id="productguid1" :value="item.productname"  placeholder="请选择品种">
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label for="spguid1" class="weui-label">规格</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text" readonly="true" id="spguid1" :value="item.spname"  placeholder="请选择规格">
            </div>
          </div>


          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">单价(元/吨)</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="number"  id="price" :value="item.price"  :name="appand(index,'price')" placeholder="请输入单价">
            </div>
          </div>


        </div>
          <div class="weui-btn-area">
          <a class="weui-btn weui-btn_primary halfbtn subbtn" href="javascript:" @click="send">保存</a>
          <a class="weui-btn weui-btn_primary halfbtn" href="javascript:"  @click="$router.back(-1)" id="sub">取消</a>
        </div>
      </form>
    </div>
  </div>
</template>

<script>

export default {
  name: 'ChangePrice',
  data () {
    return {
      guid : "",
      nodeid : "",
      status : "",
      data: [],
      wxConf:{},
      postParams: {
        pageSize: "1"
      },
      loading: false,
      showLoadIcon: false,
      showNomore: false,
      wrapperHeight: 0,
      userCode: localStorage.userCode || '',//用户code
      images: {
        localId: [], //已选择的本地图片
        serverId: [] //微信服务器返回的mediaId
      },
      saveImages: {
        previewImageList: [], //预览大图数组,
        previewThumbList: [], //预览缩略图数组
        saveImageList: [], //预览大图数组//保存图片
      },
      uploadPath: '' //图片上传的路径：为空时，默认下载到当前项目的/mcupload路径下

    }
  },
  mounted () {
      this.guid = this.$route.query.guid;
      this.nodeid = this.$route.query.nodeid;
      this.status = this.$route.query.status;
      this.axios({
        method: 'get',
        url: '/sales/Sellitem!getItem.action',
        params:  {sellguid:this.guid}
      }).then(response => {
        this.data = response.data.info;
      });
},
  methods: {
    send: function() {
      //防止重复提交
      $('.subbtn').attr("disabled",true).css("pointer-events","none");

      this.axios({
        method: 'post',
        responseType: 'json',
        headers: { "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8" },
        url: '/sales/Sellitem!chnagePrice.action?openid=' + localStorage.openid + '&nodeid=' + this.nodeid + '&status=' + this.status,
        params: this.serialize2Obj($("#formid").serializeArray())
      }).then(response => {
        //恢复提交按钮可点击
        $('.subbtn').attr('disabled', false).css("pointer-events","auto");

        if(response.data.info == "ok"){
          this.toastText('操作成功!');
        }else{
          this.toastError('操作失败!');

        }
        this.$router.push({name: 'Sellform'});
      }).catch(function (error) {
        //恢复提交按钮可点击
        $('.subbtn').attr('disabled', false).css("pointer-events","auto");
        this.toastError('系统错误');
      });
    },
    // serialize2Obj: function (data) {
    //   var obj = {};
    //   $.each(data,function(i,v){
    //     obj[v.name] = v.value;
    //   })
    //   return obj;
    // },
    appand:function (index,key){
      return "sellitems[" + index + "]." + key;
    }

  }

}
</script>


